<template>
  <div class="app-container">

    <div class="button" style="padding-bottom:0.5rem">
      <div class="grid-content bg-purple-dark">
        <el-row>
          <el-button type="primary" @click="addAdmin">添加管理员</el-button>
        </el-row>
      </div>
    </div>

    <el-table
      element-loading-text="Loading"
      :data="administratorList"
      border
      fit
      style="width: 100%"
      highlight-current-row
    >
      <!--      <el-table-column label="序号" align="center" width="50rem">-->
      <!--        <template slot-scope="scope">{{ scope.row.a }}</template>-->
      <!--      </el-table-column>-->
      <el-table-column label="姓名" align="center">
        <template slot-scope="scope">{{ scope.row.adminName }}</template>
      </el-table-column>
      <el-table-column label="用户名" align="center">
        <template slot-scope="scope">{{ scope.row.loginName}}</template>
      </el-table-column>
      <el-table-column label="最近登录时间" align="center">
        <template slot-scope="scope">{{ scope.row.lastLogin }}</template>
      </el-table-column>
      <el-table-column label="手机号" align="center">
        <template slot-scope="scope">{{ scope.row.adminTel }}</template>
      </el-table-column>

      <!--      <el-table-column label="操作" align="center" width="220rem">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button type="info" size="small"-->
      <!--                     @click="findAdmin(scope.row.adminId)">查看-->
      <!--          </el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      align="center"
    ></el-pagination>

  </div>
</template>

<script>
  import $ from "@/api/accountSet"

  export default {
    data() {
      return {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        administratorList: [],
      }
    },
    created() {
      // 管理员列表
      this.fetchData()
    },
    methods: {
      fetchData() {
        this.currentPage = 1
        $.tbAdmList({
          pageIndex: this.currentPage,
          pageSize: this.pageSize
        }).then(res => {
          this.administratorList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          // console.log(res.data)
        })
      },

      // 添加管理员
      addAdmin(){
        this.$router.push({
          path: "add"
        });
      },

      // 查看单个管理员信息
      // findAdmin(id){
      //   $.getByAdmId({admId:id}).then(res=>{
      //     if (res.success){
      //       console.log(res.data)
      //     }
      //   })
      // },

      // 翻页查看
      find(pageIndex) {
        $.tbAdmList({
          pageIndex: pageIndex,
          pageSize: this.pageSize
        }).then(res => {
          this.administratorList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }

        })
      },

      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 1;
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },

      handleCurrentChange(val) {
        this.currentPage = val;
        //console.log(val)
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },
    }
  }
</script>
